﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using SdmxMl.Structure;

namespace SdmxMl.Panels
{
    public partial class DlgEditTransition : Form
    {
        private bool _isFinal;
        public bool IsFinal
        {
            set
            {
                _isFinal = value;
                IsFinalEditControls(_isFinal);
            }
        }

        private TransitionType _transition;
        public TransitionType Transition
        {
            get { return _transition; }
            set
            {
                _transition = value;
                this.comboMultiLines.ML = _transition.Condition;
                this.comboBoxStep.Text = _transition.TargetStep;
            }
        }


        public DlgEditTransition(ProcessStepTypeList stepList)
        {
            InitializeComponent();
            comboBoxStep.Items.Clear();
            FillCombo(stepList);
        }

        private void FillCombo(ProcessStepTypeList plist)
        {
            if (plist != null)
            {
                foreach (ProcessStepType pt in plist)
                {
                    comboBoxStep.Items.Add(pt.FullId);
                    FillCombo(pt.ProcessStepList);
                }
            }
        }

        // No edition if Parent Artefact IsFinal
        private void IsFinalEditControls(bool isFinal)
        {
            bool enabled = isFinal == false;

            comboBoxStep.Enabled = enabled;
            comboMultiLines.IsFinal = isFinal;
        }

        private void buttonClose_Click(object sender, EventArgs e)
        {
            _transition.TargetStep = this.comboBoxStep.Text;
            this.Close();
        }

    }
}
